<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数">
<input type="button" value="猜一猜" onclick="f()">
<div>结果</div>

<script>
    let number = parseInt(Math.random()*100)+1;

    var num=0;

   function f() {

       let a = document.querySelector("input");
       let b = document.querySelector("div");
       if(isNaN(a.value)) {
           b.innerText="输入数据不对!";
       }else{
           num++;
           if (num < 11) {
               if (a.value * 1 < number) {
                   b.innerText = "猜小了";
               } else if (a.value * 1 > number) {
                   b.innerText = "猜大了";
               } else {
                   b.innerText = "第" + num + "次猜对了";
               }
           } else {
               b.innerText = "十次都没猜到,你猜nm呢";
           }
       }
   }

</script>
</body>
</html>